<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;

class Users extends Model
{
    protected $table = 'users';
    public $timestamps = false;
    //
    public function collection()
    {
        return $this->hasOne('App\Model\Collection','uid','id');

    }
    //验证登录信息
    public function checkValidate($data){
        $rules = array(
            'password' => 'required|alpha_dash|between:6,12|confirmed',
            'password_confirmation' => 'required|alpha_dash|between:6,12',
        );
        $message = array(
            "required"             => ":attribute 不能为空",
            "between"      => ":attribute 长度必须在 :min 和 :max 之间",
            "alpha_dash"      => ":attribute 不能使用字母数字下划线之外的字符",
            "confirmed"      => "两次密码不一样"
        );

        $attributes = array(
            "password" => '密码',
            'password_confirmation' => '重复密码',
        );

        $validate = Validator::make($data,$rules,$message,$attributes);
        return $validate;
    }
    //验证个人中心保存信息
    public function userValidate($data)
    {
        $rules = array(
            'wechat' => 'alpha_num',
            'email' => 'email',
        );
        $message = array(
            "alpha_num"      => ":attribute 不能使用字母数字之外的字符",
            "email"      => "邮箱格式错误"
        );

        $attributes = array(
            "wechat" => '微信号',
            "email" => '邮箱',
        );
        $validate = Validator::make($data,$rules,$message,$attributes);
        return $validate;
    }
    /*public function userValidate($data){
        $rules = array(
            'username' => 'required',
            'sex' => 'required',
            'birth' => 'required',
            'profession' => 'required',
            'wechat' => 'required|alpha_num',
            'email' => 'required|email',
            'address' => 'required',
        );
        $message = array(
            "required"             => ":attribute 不能为空",
            "alpha_num"      => ":attribute 不能使用字母数字之外的字符",
            "email"      => "邮箱格式错误"
        );

        $attributes = array(
            "username" => '昵称',
            "sex" => '性别',
            "birth" => '出生年月',
            "profession" => '职业',
            "wechat" => '微信号',
            "email" => '邮箱',
            "address" => '地址',
        );

        $validate = Validator::make($data,$rules,$message,$attributes);
        return $validate;
    }*/
    //验证手机号是否合法
    public function phoneValidate($data){
        $rules = array(
            'phone'=>'regex:/^1[34578][0-9]{9}$/'
        );
        $message = array(
            "regex"             => "手机号不合法"
        );

        $attributes = array(
            "phone" => '手机号',
        );

        $validate = Validator::make($data,$rules,$message,$attributes);
        return $validate;
    }
}
